/*
 * To change this template, choose Tools | Templates and open the template in
 * the editor.
 */
package dadosUsuarioLogado;

import br.com.modelo.Operador;
import java.io.Serializable;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;
import javax.faces.context.FacesContext;
import javax.servlet.http.HttpSession;

/**
 *
 * @author gilberto.costa
 */
@ManagedBean(name = "usuarioLogado")
@ViewScoped
public class UsuarioLogado implements Serializable {

    public String getUsuarioLogado() {
        HttpSession session = (HttpSession) FacesContext.getCurrentInstance().getExternalContext().getSession(false);
        if (session != null) {
            Object obj = session.getAttribute("usuarioLogado");
            if (obj != null) {
                Operador f = (Operador) obj;
                return f.getLogin().toUpperCase();
            }
        }
        return "";
    }

    public String getNivelAcessousuario() {
        HttpSession session = (HttpSession) FacesContext.getCurrentInstance().getExternalContext().getSession(false);
        if (session != null) {
            Object obj = session.getAttribute("usuarioLogado");
            if (obj != null) {
                Operador f = (Operador) obj;
                return f.getIdEcfFuncionario().getNivelAutorizacao().toString();
            }
        }
        return "";
    }

    public static Operador retornaUsuarioLogado() {
        try {
            HttpSession sessions = (HttpSession) FacesContext.getCurrentInstance().getExternalContext().getSession(false);
            if (sessions != null) {
                Object obj = sessions.getAttribute("usuarioLogado");
                if (obj != null) {
                    return (Operador) obj;
                } else {
                    return null;
                }
            } else {
                return null;
            }
        } catch (Exception e) {
            return null;
        }
    }
}